package com.admin.business.venusOaCaozuiLogs;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 操作日志
 * @create: 2022-03-22 18:46:06
 **/
@Service("venusOaCaozuiLogs")
@Slf4j
public class VenusOaCaozuiLogsService{

    @Resource
    VenusOaCaozuiLogsDao venusOaCaozuiLogsDao;

    /**
     * 添加操作日志,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:企业id
     *                   - pro_id:项目id
     *                   - user_id:操作人id
     *                   - hardware:操作硬件
     *                   - type:类型：pc之类的
     *                   - ip_dress:ip地址
     *                   - caozui_event:操作事件
     *                   - caozui_Recording:操作记录详情
     *                   - update_time:更新时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return addVenusOaCaozuiLogs(CDO cdoRequest) {
        venusOaCaozuiLogsDao.addVenusOaCaozuiLogs(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新操作日志数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:企业id
     *                   - pro_id:项目id
     *                   - user_id:操作人id
     *                   - hardware:操作硬件
     *                   - type:类型：pc之类的
     *                   - ip_dress:ip地址
     *                   - caozui_event:操作事件
     *                   - caozui_Recording:操作记录详情
     *                   - update_time:更新时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return updateVenusOaCaozuiLogsById(CDO cdoRequest) {
        int affectedRows = venusOaCaozuiLogsDao.updateVenusOaCaozuiLogsById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除操作日志数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOaCaozuiLogsById(CDO cdoRequest){
        int affectedRows = venusOaCaozuiLogsDao.deleteVenusOaCaozuiLogsById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除操作日志数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOaCaozuiLogs(CDO cdoRequest) {
        int affectedRows = venusOaCaozuiLogsDao.deleteVenusOaCaozuiLogs(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取操作日志数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOaCaozuiLogsById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaCaozuiLogsDao.getVenusOaCaozuiLogsById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取操作日志数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOaCaozuiLogs(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaCaozuiLogsDao.getVenusOaCaozuiLogs(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取操作日志数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOaCaozuiLogsList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaCaozuiLogsDao.getVenusOaCaozuiLogsList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaCaozuiLogsDao.getVenusOaCaozuiLogsListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取操作日志数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOaCaozuiLogsListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaCaozuiLogsDao.getVenusOaCaozuiLogsListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaCaozuiLogsDao.getVenusOaCaozuiLogsListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
